import {reactive} from "vue";
import {defaultSorting, type Sorting} from "@/hooks/useSorting";

export interface Query {
  fieldName?: string;
  fieldValue?: string[];
  operator?: string;
  nested?: string;
}

export interface DefaultQuery {
  fieldName: string;
  fieldValue: string[];
  operator: string;
  nested: string;
}

export interface Excel {
  name?: string;
  sheetName?: string;
  fieldList?: string[];
}

export interface DefaultExcel {
  name: string;
  sheetName: string;
  fieldList: string[];
}

export interface Operation {
  pageNo?: number;
  pageSize?: number;
  fieldList?: string[];
  joinQuery?: Object;
  queryList?: Query[];
  sortList?: Sorting[];
  excel?: Excel;
}

export interface DefaultOperation {
  pageNo: number;
  pageSize: number;
  fieldList: string[];
  joinQuery: Object;
  queryList: Query[];
  sortList: Sorting[];
  excel: Excel;
}

const defaultOperation: DefaultOperation = {
  pageNo: 1,
  pageSize: 10,
  fieldList: [],
  joinQuery: {},
  queryList: [],
  sortList: defaultSorting,
  excel: {}
};

export const useOperation = (initialOperation: Operation = {}) => {
  const operation = reactive({...defaultOperation, ...initialOperation});
  return {operation: operation};
};
